package com.jzo2o.customer.controller.operation;

import com.jzo2o.common.expcetions.ForbiddenOperationException;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.enums.CertificationStatusEnum;
import com.jzo2o.customer.model.dto.request.WorkerCertificationAuditPageQueryReqDTO;
import com.jzo2o.customer.model.dto.response.WorkerCertificationAuditResDTO;
import com.jzo2o.customer.service.ICertificationAuditService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author JIAN
 */
@RestController("operationWorkerCertificationAudit")
@RequestMapping("/operation/worker-certification-audit")
@Api(tags = "运营端 - 服务人员认证相关接口")
public class WorkerCertificationAuditController {
    @Resource
    private ICertificationAuditService certificationAuditService;

    /**
     * 分页查询服务人员认证的记录
     */
    @GetMapping("/page")
    public PageResult<WorkerCertificationAuditResDTO> page(WorkerCertificationAuditPageQueryReqDTO workerCertificationAuditPageQueryReqDTO) {
        return certificationAuditService.getWorkerCertificationInfo(workerCertificationAuditPageQueryReqDTO);
    }

    /**
     * 审核服务人员认证信息
     * @param id                  认证记录id
     * @param certificationStatus 认证状态
     * @param rejectReason        拒绝原因
     */
    @PutMapping("/audit/{id}")
    public void audit(@PathVariable Long id,
                      @RequestParam Integer certificationStatus,
                      @RequestParam(required = false) String rejectReason) {
        if (certificationStatus != CertificationStatusEnum.SUCCESS.getStatus()
                && certificationStatus != CertificationStatusEnum.FAIL.getStatus()) {
            throw new ForbiddenOperationException("更新的认证状态有误无法认证");
        } else {
            certificationAuditService.audit(id, certificationStatus, rejectReason);
        }
    }
}